<#include "../../inc/layout.html"><@layout>
<script type="text/javascript" charset="utf-8">
	var searchForm;
	var searchForm2;
	var datagrid;
	var datagrid2;
	var datagrid3;
	var articleForm;
	var txpl=['不重复','30分钟重复','每天重复','每周重复','每月重复'];
	var cols=[ [ {title : '标题',field : 'TITLE',width:200,
		formatter : function(v,row) {
			return "<a href=\"javascript:view("+row.ID+",'"+v+"');\" title='"+v+"'>"+v+"</a>";
		}
	},{
		field:'TXPL',title:'提醒频率',width:200,sortable : true,formatter : function(v) {
			return txpl[v];
		}
	},{
		field:'TXDATE',title:'提醒时间',sortable : true,width:200
	},{
		field:'CTIME',title:'创建时间',width:200,sortable : true
	}] ];
	$(function() {
		//查询列表	
		searchForm = $('#searchForm').form();
		datagrid = $('#datagrid').datagrid({
			url:'/oa/beiwanglu/dataGrid',
			pagination:true,
			pagePosition:'bottom',
			rownumbers:true,
			pageSize:20,
			pageList:[ 20, 50, 100 ],
			fit:true,
			fitColumns:true,singleSelect:true,
			nowrap:true,
			border:false,
			idField:'ID',
			sortName:'',
			sortOrder:'',
			columns:cols,
			toolbar:[
			{
				text:'查看',
				iconCls:'icon-eye',
				handler:function() {
					view();
				}
			},{
				text:'增加',
				iconCls:'icon-add',
				handler:function() {
					add();
				}
			}, '-',
			{
				text:'删除',
				iconCls:'icon-remove',
				handler:function() {
					del();
				}
			}, '-', {
				text:'修改',
				iconCls:'icon-edit',
				handler:function() {
					edit();
				}
			}, '-',
			{
				text:'取消选中',
				iconCls:'icon-undo',
				handler:function() {
					datagrid.datagrid('unselectAll');
				}
			}, '-' ]
		});
		searchForm2 = $('#searchForm_2').form();
		datagrid2 = $('#datagrid_2').datagrid({
			url:'/oa/beiwanglu/dataGrid2',
			pagination:true,
			pagePosition:'bottom',
			rownumbers:true,
			pageSize:20,
			pageList:[ 20, 50, 100 ],
			fit:true,
			fitColumns:true,singleSelect:true,
			nowrap:true,
			border:false,
			idField:'ID',
			sortName:'',
			sortOrder:'',
			columns:cols
		});
	});

	function _search() {
		datagrid.datagrid('load', sy.serializeObject(searchForm));
	}
	function cleanSearch() {
		datagrid.datagrid('load', {});
		searchForm.find('input').val('');
	}
	function _search_2() {
		datagrid2.datagrid('load', sy.serializeObject(searchForm2));
	}
	function cleanSearch_2() {
		datagrid2.datagrid('load', {});
		searchForm2.find('input').val('');
	}
	function del() {
		var rows = datagrid.datagrid('getSelections');
		var ids = [];
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].ID);
					}
					$.ajax({
						url:'/oa/beiwanglu/del',
						data:{
							ids:ids.join(',')
						},
						dataType:'json',
						success:function(r) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							if (r.success) {
								$.messager.show({
									title:'提示',
									msg:'删除成功！'
								});
							} else {
								$.messager.alert("操作错误",r.msg,'error');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}
	var editor;
	function add(id_) {
		$.messager.progress({
			text:'数据加载中....',
			interval:100
		});
		$('#Dialog_').dialog({
		    title:(id_==undefined?"新增":"编辑")+"公告",   
		    cache: false,
		    maximizable:false,
		    resizable:false,
		    width:800,
		    top:0,
		    href: '/oa/beiwanglu/edit/'+(id_==undefined?'':id_),   
		    modal: false,
		    onLoad:function(){$.messager.progress('close');
		    	editor=KindEditor.create('.keditor', {
				themeType : 'default',
				uploadJson : '${root!}/file/up',
				fileManagerJson : '${root!}/file/manager',
				allowFileManager : false,
				items : ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
							'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
							'insertunorderedlist', '|', 'emoticons', 'image', 'link']
			});},
			buttons:[ {
				text:'保存',
				iconCls:'icon-save',
				handler:function() {
					articleForm = $('#editForm').form({
						url:'/oa/beiwanglu/save/?uids='+getChecked(),
						success:function(data) {
							var json = $.parseJSON(data);
							if (json && json.success) {
								$.messager.show({
									title:'成功',
									msg:json.msg
								});
								datagrid.datagrid('reload');
								$("#poid").val(json.obj);
								//$('#Dialog_').dialog('close');
							} else {
								$.messager.show({
									title:'失败',
									msg:'操作失败！'
								});
							}
						}
					});
					editor.sync();//ajax提交时需要执行此方法
					editor.sync();
					articleForm.submit();
					}
				},
				{
				text:"关闭",
				iconCls:'icon-cancel',
				handler:function() {
					$('#Dialog_').dialog('close');
				}
			}]
		}); 
	}
	function edit() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			add(rows[0].ID);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'error');
		}
	}
	function view(id_,title){
		if(id_==undefined){
			var rows = datagrid.datagrid('getSelections');
			if (rows.length == 1) {
				id_=rows[0].ID;
				title=rows[0].TITLE;
			}else{
				$.messager.alert('提示', '请选择一条记录！', 'error');
				return;
			}
		}
			$.messager.progress({
				text:'数据加载中....',
				interval:100
			});
			$('#Dialog_').dialog({
			    title: '查看-'+title,   
			    width: 800,   
			    top:0, 
			    cache: false,
			    maximizable:true,
			    href: '/oa/beiwanglu/view/' + id_,   
			    modal: true,
			    onLoad:function(){$.messager.progress('close');},
				buttons:[ {
					text:"关闭",
					handler:function() {
						$('#Dialog_').dialog('close');
					}
				}]
			});   
	}
</script>
</head>
<body class="easyui-layout" >
<div class="easyui-tabs"  region="center" border="false" style="width:800px; height: 500px;">
<div title="我的备忘" style="padding:1px;" class="easyui-layout" >
	<div region="north" border="false" title="搜索条件" collapsed="false" id="sto1"
		style="height: 60px; overflow:hidden;" align="left">
		<form id="searchForm">
		<div class="tableForm datagrid-toolbar" style="height: 100%;width:100%;">
			<table style="height: 100%;width: auto;">
				<tr>
					<td>标题</td>
					<td><input name="title" style="width: 120px;"/></td>
					<td>提醒时间</td>
					<td><input name="startDate"class="easyui-datebox"  size="10" >-<input name="endDate"class="easyui-datebox"  size="10" > </td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						iconCls="icon-search" onclick="_search();">查询</a><a
						href="javascript:void(0);" class="easyui-linkbutton"
						onclick="cleanSearch();">取消</a></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
	<div region="center" border="false">
		<table id="datagrid" ></table>
	</div>
</div>
<div title="共享给我" style="padding:1px;" class="easyui-layout" >
	<div region="north" border="false" title="搜索条件" collapsed="false"id="sto2"
		style="height: 60px; overflow:hidden;" align="left">
		<form id="searchForm_2">
		<div class="tableForm datagrid-toolbar" style="height: 100%;width:100%;">
			<table style="height: 100%;width: auto;">
				<tr>
					<td>标题</td>
					<td><input name="title" style="width: 120px;"/></td>
					<td>提醒时间</td>
					<td><input name="startDate"class="easyui-datebox" size="10" >-<input name="endDate"class="easyui-datebox"  size="10" > </td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						iconCls="icon-search" onclick="_search_2();">查询</a><a
						href="javascript:void(0);" class="easyui-linkbutton"
						onclick="cleanSearch_2();">取消</a></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
	<div region="center" border="false">
		<table id="datagrid_2" ></table>
	</div>
</div>
</div>
	<div id="Dialog_"></div>
</@layout>